//
//  GHSOD_PL_CommentInfoTableViewCell.m
//  penzer
//
//  Created by 还带大道 on 2018/11/17.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "GHSOD_PL_CommentInfoTableViewCell.h"

@interface GHSOD_PL_CommentInfoTableViewCell()
@property (weak, nonatomic) IBOutlet UIView *bgV;
@property (weak, nonatomic) IBOutlet UIImageView *head;
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UILabel *time;
@property (weak, nonatomic) IBOutlet UILabel *start_des;
@property (weak, nonatomic) IBOutlet UILabel *start_send;
@property (weak, nonatomic) IBOutlet UILabel *start_service;
@property (weak, nonatomic) IBOutlet UILabel *contentL;
@property (weak, nonatomic) IBOutlet UIView *picV;
@property (weak, nonatomic) IBOutlet UILabel *tagsL;

@property (nonatomic,strong) NSMutableArray<UIView *> *pics;
@end

@implementation GHSOD_PL_CommentInfoTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    //设置阴影
    _bgV.backgroundColor = [UIColor whiteColor];
    _bgV.layer.shadowColor = RZ_COLOR_ALPHA(0, 0, 0, 0.09).CGColor;
    _bgV.layer.cornerRadius = 5;
    _bgV.layer.shadowOffset = CGSizeMake(0,4);
    _bgV.layer.shadowOpacity = 1;
    _bgV.layer.shadowRadius = 15;
    
    [self setupDesL];
    [self setupTagsL];
    [self setupStart];
    [self addImages];
}


- (void)setupDesL
{
    NSString *contentStr = @"哎呀。。。不用不知道，一用忘不掉，外观漂亮，系统简直流畅的没话说，操作更是舒服至极，谁用谁知道！";
    if(contentStr && contentStr.length>0){
        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
        paragraph.lineSpacing = 5; //设置行间距
        paragraph.alignment = NSTextAlignmentLeft;
        NSDictionary *attributeDict = @{
                                        NSFontAttributeName:[UIFont fontWithName:@"PingFang-SC-Medium" size:12],
                                        NSForegroundColorAttributeName:RZ_COLOR(74, 74, 74),
                                        NSKernAttributeName:@0,//字符间距
                                        NSParagraphStyleAttributeName:paragraph};
        
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:attributeDict];
        _contentL.attributedText = attributeStr;
    }
}


- (void)setupTagsL
{
    NSString *contentStr = @"魅影紫   三摄像头（后双） 4G+全网通 双卡双待 存储:8+128GB   高通八核2.0GHz";
    if(contentStr && contentStr.length>0){
        NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
        paragraph.lineSpacing = 3; //设置行间距
        paragraph.alignment = NSTextAlignmentLeft;
        NSDictionary *attributeDict = @{
                                        NSFontAttributeName:[UIFont fontWithName:@"PingFang-SC-Medium" size:12],
                                        NSForegroundColorAttributeName:RZ_COLOR_ALPHA(51, 51, 51, 0.5),
                                        NSKernAttributeName:@0,//字符间距
                                        NSParagraphStyleAttributeName:paragraph};
        
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:contentStr attributes:attributeDict];
        _tagsL.attributedText = attributeStr;
    }
}



- (void)setupStart
{
    NSString *imageName_s = @"logo";
    NSString *imageName_n = @"logo";
    NSMutableAttributedString *mas_dsc  = [NSMutableAttributedString new];
    for (NSInteger index = 0 ; index<5; index++) {
        NSTextAttachment *atta = [NSTextAttachment new];
        atta.image = [UIImage imageNamed:imageName_s];
        atta.bounds = CGRectMake(0, 0, 11, 14);
        NSAttributedString *as = [NSAttributedString attributedStringWithAttachment:atta];
        [mas_dsc appendAttributedString:as];
    }
    self.start_des.attributedText = mas_dsc;
    
    NSMutableAttributedString *mas_send  = [NSMutableAttributedString new];
    for (NSInteger index = 0 ; index<5; index++) {
        NSTextAttachment *atta = [NSTextAttachment new];
        atta.image = [UIImage imageNamed:imageName_s];
        atta.bounds = CGRectMake(0, 0, 11, 14);
        NSAttributedString *as = [NSAttributedString attributedStringWithAttachment:atta];
        [mas_send appendAttributedString:as];
    }
    self.start_send.attributedText = mas_send;
    
    NSMutableAttributedString *mas_service  = [NSMutableAttributedString new];
    for (NSInteger index = 0 ; index<5; index++) {
        NSTextAttachment *atta = [NSTextAttachment new];
        atta.image = [UIImage imageNamed:imageName_s];
        atta.bounds = CGRectMake(0, 0, 11, 14);
        NSAttributedString *as = [NSAttributedString attributedStringWithAttachment:atta];
        [mas_service appendAttributedString:as];
    }
    self.start_service.attributedText = mas_service;
    
}



- (void)addImages
{
//    _picV.backgroundColor = [UIColor orangeColor];
    _pics = [NSMutableArray array];
    for (NSInteger index =0;index<3;index++) {
        UIButton *btn = [UIButton new];
//        btn.backgroundColor = [UIColor greenColor];
        [btn setBackgroundImage:[UIImage imageNamed:@"icon_goods"] forState:UIControlStateNormal];
        [self.picV addSubview:btn];
        [self.pics addObject:btn];
    }
    
}




- (void)layoutSubviews
{
    [super layoutSubviews];

    CGFloat wh = 80;
    __block CGFloat x = 0;
    __block CGFloat y = 0;
    __block NSInteger row = 0;
    __block NSInteger col = 0;
    NSInteger maxcount = 2;
    CGFloat margin_xy = 10;
    
    [self.pics enumerateObjectsUsingBlock:^(UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        col = idx % maxcount;
        row = idx / maxcount;
        x = (wh + margin_xy)*col;
        y = (wh + margin_xy)*row;
        obj.frame = CGRectMake(x, y, wh, wh);
    }];
    
    [_tagsL sizeToFit];
    [_contentL sizeToFit];
   CGFloat height = CGRectGetMaxY(self.tagsL.frame) + 20 - self.picV.height + CGRectGetMaxY(self.pics.lastObject.frame);
    _cellH = height;
    
}


- (CGFloat)cellH
{
    [self layoutIfNeeded];
    _bgV.layer.shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, self.bgV.width, _cellH-7)].CGPath;
    return _cellH;
}

@end
